import 'dart:convert';

import 'package:common_utils/common_utils.dart';
import 'package:du_application/http/HttpUtil.dart';
import 'package:du_application/http/Options.dart';

import 'package:du_application/model/UserInfoModel.dart';
import 'package:du_application/provide/AuthProvider.dart';

import 'package:flutter/material.dart';
import 'package:provide/provide.dart';
import 'package:shared_preferences/shared_preferences.dart';

class PersonProvide with ChangeNotifier {
    Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
  UserInfoModel userInfoModel;

   bool isLeft = true;
   bool isRight = false;
  changeLeftAndRight(String changeState){
    if(changeState=='left'){
      print('跑到左边了');
      isLeft=true;
      isRight=false;
    }else{
      isLeft=false;
      isRight=true;
    }
     notifyListeners();
  }
  getUserInfo(context) async{

    Options options =  Options(Provide.value<AuthProvider>(context).token);
  await HttpUtil.getInstance()
        .get("/auth/info",
           options: options.options )
        .then((res) async {
          LogUtil.v(res);
          userInfoModel= UserInfoModel.fromJson(json.decode(res));
           if(userInfoModel.errno!=0){
            Provide.value<AuthProvider>(context).setToken(null);
           }else{
              notifyListeners();
           }
    });

  }
}